import axios from "axios";

const request = axios.create({
  timeout: 2000,
});

request.interceptors.request.use(
  function (config) {
    return config;
  },
  function (error) {
    return Promise.reject(error);
  }
);

request.interceptors.response.use(
  function (response) {
    return response;
  },
  function (error) {
    const status = error.response.status;
    if (status === 404) {
      alert("接口找不到");
    } else if (status === 500) {
      alert("服务端错误");
    } else if (status === 304) {
      alert("信息被缓存了");
    } else if (status === 400) {
      alert("语义有误或者请求参数错误");
    } else if (status === 423) {
      alert("正在访问的资源被锁定");
    }
    return Promise.reject(error);
  }
);

export default request;
